package com.atguigu.day07;

import sun.font.DelegatingShape;

import java.util.Arrays;

public class Test07 {
    public static void main(String[] args) {
        MyArrays m1 = new MyArrays();
        int[] arr = new int[]{5, 6, 7, 1, 5, 4};
        m1.sort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(m1.indexOf(arr, 5));

        System.out.println(Arrays.toString(m1.copy(arr, 5)));

    }
}

class MyArrays {
    void sort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    int indexOf(int[] arr, int value) {
        for (int i = 0; i < arr.length; i++) {
            if (value == arr[i])
                return i;
        }
        return -1;
    }

    int[] copy(int[] arr, int len) {
        int[] subarr = new int[len];
        for (int i = 0; i < len; i++) {
            subarr[i] = arr[i];
        }
        return subarr;
    }
}
